package cn.edu.pet.servlet.admin;

import cn.edu.pet.entity.Pets;
import cn.edu.pet.entity.User;
import cn.edu.pet.repo.PetRepo;
import cn.edu.pet.repo.UserRepo;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/admin/pet/get")
public class PetGetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        Pets pets = PetRepo.getInstance().selectById(Integer.valueOf(id));
        ObjectMapper objectMapper = new ObjectMapper();
        PrintWriter writer = resp.getWriter();
        String json = objectMapper.writeValueAsString(pets);
        writer.write(json);
    }
}
